package com.example.myapplication2;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

public class AddItemActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText editText3;
    private EditText editText4;
    private EditText editText5;
    private EditText editText6;
    private EditText editText7;
    private Button button3;
    private TextView textView7;
    private EditText editText8;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_item);
        initView();


    }

    private void initView() {
        editText3 = (EditText) findViewById(R.id.editText3);
        editText4 = (EditText) findViewById(R.id.editText4);
        editText5 = (EditText) findViewById(R.id.editText5);
        editText6 = (EditText) findViewById(R.id.editText6);
        editText7 = (EditText) findViewById(R.id.editText7);
        button3 = (Button) findViewById(R.id.button3);
        textView7 = (TextView) findViewById(R.id.textView7);
        editText8 = (EditText) findViewById(R.id.editText8);

        button3.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Button button = findViewById(R.id.button3);
        EditText editText3 = findViewById(R.id.editText3);
        EditText editText4 = findViewById(R.id.editText4);
        EditText editText5 = findViewById(R.id.editText5);
        EditText editText6 = findViewById(R.id.editText6);
        EditText editText7 = findViewById(R.id.editText7);
        EditText editText8 = findViewById(R.id.editText8);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = editText3.getText().toString();
                String itemDesc = editText4.getText().toString();
                String itemRemark = editText5.getText().toString();
                String price = editText6.getText().toString();
                String id = editText7.getText().toString();
                String time = editText8.getText().toString();

                Map<String,String> map = new HashMap<>();
                map.put("itemName",name);
                map.put("itemDesc",itemDesc);
                map.put("itemRemark",itemRemark);
                map.put("initPrice",price);
                map.put("kindId",id);
                map.put("avail",time);
                try {
                    String result = OkHttpUtil
                            .postRequest("http://172.18.85.254:8080/auction/api/items",map);
                    System.out.println("----result-----" + result);


                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
    }



    private void submit() {
        // validate
        String editText3String = editText3.getText().toString().trim();
        if (TextUtils.isEmpty(editText3String)) {
            Toast.makeText(this, "editText3String不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        String editText4String = editText4.getText().toString().trim();
        if (TextUtils.isEmpty(editText4String)) {
            Toast.makeText(this, "editText4String不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        String editText5String = editText5.getText().toString().trim();
        if (TextUtils.isEmpty(editText5String)) {
            Toast.makeText(this, "editText5String不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        String editText6String = editText6.getText().toString().trim();
        if (TextUtils.isEmpty(editText6String)) {
            Toast.makeText(this, "editText6String不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        String editText7String = editText7.getText().toString().trim();
        if (TextUtils.isEmpty(editText7String)) {
            Toast.makeText(this, "editText7String不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        String editText8String = editText8.getText().toString().trim();
        if (TextUtils.isEmpty(editText8String)) {
            Toast.makeText(this, "editText8String不能为空", Toast.LENGTH_SHORT).show();
            return;
        }



    }
}
